<!-- 首页 -->
<template>
	<view>
		<cu-custom bgColor="bg-gradual-pink" :isBack="true"><block slot="content">访客</block></cu-custom>
		<view class="box-list">
			<view class="reply-box" v-for="(item, index) in dataList" :key="index">
				<u-avatar @click="userCenter(item)" :src="item.visitAvatar"></u-avatar>
				<view class="reply-info-box" :class="dataList.length-1 > index ? 'weui-cell' : ''">
					<view class="reply-info">
						<view class="nickname">{{item.visitNickName}}</view>
						<view class="user-info">
							<view class="sex-box-nv" v-if="item.visitSex == '1'">
								<u-icon name="ziyuan2" custom-prefix="iconfont"></u-icon>
								<view class="age-text">{{item.visitAge}}</view>
							</view>
							<view class="sex-box" v-else>
								<u-icon name="ziyuan3" custom-prefix="iconfont"></u-icon>
								<view class="age-text">{{item.visitAge}}</view>
							</view>
							<view class="user-city">{{item.city}}</view>
						</view>
						<view class="reply-time">{{item.time}} | 访问{{item.visitNum}}次</view>
					</view>
					<view class="user-map">
						<u-icon name="map-fill" color="#909399"></u-icon>
						<view class="map-num">{{item.distance}}km</view>
					</view>
				</view>
			</view>
			
		</view>
		
		<view class="loadmore-box" v-if="dataList.length > 0">
			<u-loadmore :status="status" @loadmore="load"></u-loadmore>
		</view>
		<u-back-top :scrollTop="scrollTop"></u-back-top>
		<coin-popup></coin-popup>
		<user-auth></user-auth>
	</view>
</template>

<script>
export default {
	data() {
		return {
			status: 'loadmore',
			isEnd: false,
			current: 1,
			pageSize: 10,
			scrollTop: 0,
			dataList: []
		};
	},
	onLoad() {
		this.init();
	},
	onReachBottom() {
		this.load();
	},
	methods: {
		init() {
			this.query();
		},
		reload() {
			this.query();
		},
		load() {
			this.loadmore();
		},
		onScrollTop(e) {
			this.scrollTop = e.scrollTop;
		},
		async loadmore() {
			this.status = 'loading';
			if(this.isEnd){
				this.status = 'nomore';
				return;
			}
			var res = await this.getDataList();
			this.dataList = this.dataList.concat(res.rows);
		},
		query() {
			this.current = 1;
			this.isEnd = false;
			this.status = 'loadmore';
			this.loadquery();
		},
		async loadquery() {
			var res = await this.getDataList();
			this.dataList = res.rows;
		},
		async getDataList() {
			var res = await this.$u.get('/wq/userVisit/getList', {
				pageNum: this.current,
				pageSize: this.pageSize,
			});
			var totalPage = Math.ceil(res.total/this.pageSize);
			this.pages = totalPage;
			this.current ++;
			this.status = 'loadmore';
			if(this.current > this.pages){
				this.status = 'nomore';
				this.isEnd = true;
			}
			return res;
		},
		userCenter(item) {
			this.judgeLogin(() => {
				this.$u.route({
					url: 'packgeMine/pages/center/index',
					params: {
						userId: item.visitUserId,
					}
				});
			});
		},
		chat(item) {
			this.$u.post('/im/roomUser/updateRead',{
				id: item.id
			}).then(res => {
				this.$u.vuex('message', res.data);
				this.$u.route({
					url: 'tn_components/chat/chat',
					params: {
						roomId: item.roomId,
						nickName: item.nickName,
						sendUserId: item.sendUserId
					}
				});
			})
		}
	}
}; 
</script>
<style lang="scss" scoped>
	.nickname {
		font-size: 28rpx;
	}
	.loadmore-box {
		padding: 15px 0;
	}
	.reply-box {
		display: flex;
		align-items: center;
		padding: 0 30rpx;
	}
	.reply-info-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex: 1;
		margin-left: 30rpx;
		position: relative;
		padding: 15px 0;
	}
	.reply-info {
		padding-right: 40rpx;
		display: flex;
		flex: 1;
		flex-direction: column;
	}
	.nickname {
		font-weight: bolder;
		font-size: 32rpx;
	}
	.reply-text {
		font-size: 32rpx;
		line-height: 44rpx;
		margin-top: 6rpx;
		word-break: break-all;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}
	.reply-time {
		font-size: 26rpx;
		color: #909399;
	}
	.user-man {
		background-color: #6dabec;
		display: flex;
		align-items: center;
		color: #fff;
		border-radius: 20px;
		padding: 4rpx 12rpx;
		font-size: 22rpx;
		line-height: 26rpx;
	}
	.user-info {
		display: flex;
		align-items: center;
		flex-direction: row;
		margin: 12rpx 0;
	}
	.kan-num {
		margin-left: 2px;
	}
	.user-map {
		display: flex;
		align-items: center;
		font-size: 26rpx;
		color: #909399;
	}
	.user-city {
		font-size: 22rpx;
		margin-left: 5px;
		background-color: #ddd;
		padding: 4rpx 16rpx;
		border-radius: 20px;
		line-height: 26rpx;
	}
	.map-num {
		margin-left: 3px;
	}
	.weui-cell:after {
	    content: " ";
	    position: absolute;
	    left: 0;
	    bottom: 0;
	    right: 0;
	    height: 1px;
	    border-bottom: 1px solid #e5e5e5;
	    color: #e5e5e5;
	    -webkit-transform-origin: 0 0;
	    transform-origin: 0 0;
	    -webkit-transform: scaleY(0.5);
	    transform: scaleY(0.5);
	    z-index: 2;//看情况使用
	}
	.sex-box {
		background-color: #2b85e4;
		display: flex;
		color: #fff;
		padding: 2px 5px;
		border-radius: 20px;
		font-size: 8px;
	}
	.sex-box-nv {
		background-color: #fe709f;
		display: flex;
		color: #fff;
		padding: 2px 5px;
		border-radius: 20px;
		font-size: 8px;
	}
	.age-text {
		margin-left: 2px;
	}
</style>
